$(function() {
	movie_now_index.run();
});

var movie_now_index = {
	run : function() {
		this._init_();
		this._start_();
		this._init_events();
		this.page = 1;
	},

	_init_ : function() {
		$("#movie_side_ul > li").eq(0).addClass("curr");
	},

	_start_ : function() {
			$("#trailer_div > div.mi_box > div.img, #movies_div > div.mi_box > div.img").bind({
				mouseenter:function(){
					$(this).children('div.tc_btn').fadeIn("slow");
				},
				mouseleave:function(){
					$(this).children('div.tc_btn').stop(true,false).fadeOut("fast");
				}
			});
			
			//download.vc_download();
	},

	_init_events : function() {
		movie_now_index.fix_box_maggin();
		
		$(window).resize(function() {
			movie_now_index.fix_box_maggin();
		});
		
		$(".pt_btnN").click(function(){
			if(movie_now_index.page == 1){
				$("#trailer_div > .m_box2_3").each(function(i,v){
					if($(this).hasClass("page_pre")){
						$(this).css("display","none");
						$(this).removeClass("page_pre");
					}else{
						$(this).css("display","block");
						$(this).addClass("page_pre");
					}
				});
				movie_now_index.page = 2;
			}
		});
		$(".pt_btnP").click(function(){
			if(movie_now_index.page == 2){
				$("#trailer_div >  .m_box2_3").each(function(i,v){
					if($(this).hasClass("page_pre")){
						$(this).css("display","none");
						$(this).removeClass("page_pre");
					}else{
						$(this).css("display","block");
						$(this).addClass("page_pre");
					}
				});
				movie_now_index.page = 1;
			}
		});
	},

	fix_box_maggin : function(){
		var m_cont = $(".m_cont").width();
		//alert(m_cont);
		var box_count = 0;
		if(m_cont >= 1550){
			$("#trailer_div > .m_box2_3").css("display","block");
			$("#movies_div > .m_box2_3").css("display","block");
			$(".page_boxTop").hide();
		}else{
			box_count = Math.floor(m_cont/155);
			$("#trailer_div > .m_box2_3").css("display","none").removeClass("page_pre");
			$("#movies_div > .m_box2_3").css("display","none");
			$(".page_boxTop").show();
			for(var i=0;i<box_count;i++){
				$("#trailer_div >  .m_box2_3").eq(i).css("display","block").addClass("page_pre");
			}
			for(var i=0;i<box_count*2;i++){
				$("#movies_div >  .m_box2_3").eq(i).css("display","block");
			}
			movie_now_index.page = 1;
		}
		//alert(box_count);
		
	}

};